# -*- coding:utf-8 -*-
"""
    超级模块派生检测脚本
"""
import sys,os
from pdb import set_trace as strace
from traceback  import format_exc as dumpstack

from common.common import cat,log

def main():
    logos = ['common/logo.py']
    mods = ['common/vars.py', 'common/report.py', 'common/common.py']
    plugins = [ 'plugins/ps.py', 'plugins/backdoor.py', 'plugins/network.py', 'plugins/logs.py', 'plugins/filesystem.py']
    mains = ['common/main.py']
    output = "e4Scan.py"

    payload = []

    import common.logo as logo
    # print(logo.__doc__)
    for _ in logos:
        log("加载logo {}".format(_))
        content = cat(os.path.abspath(_))
        payload.append(content)

    version = "1"

    if version:
        str_ver = f"0.0.{version}"
        log(f"version : {str_ver}")
        payload.append(f'''__version__ = "{str_ver}"\n''')

    for _ in mods:
        log("加载库文件 {}".format(_))
        content = cat(os.path.abspath(_))
        payload.append(content)

    for _ in plugins:
        log("加载检测插件 {}".format(_))
        content = cat(os.path.abspath(_))
        payload.append(content)

    for _ in mains:
        log("加载主模块 {}".format(_))
        content = cat(os.path.abspath(_))
        payload.append(content)

    data = "\n".join(payload)
    open(output, "w+").write(data)
    log("检测脚本已写入 {}".format(output))

if __name__ == '__main__':
    os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
    main()
